#Location of Final dataset on Github
LifeExpIncomFinal <- "https://raw.githubusercontent.com/APM3030/STA553/main/homework3/LifeExpIncomFinal.csv"
LifeExpIncomFinal <- read_csv(LifeExpIncomFinal)
#convert year to integer
LifeExpIncomFinal <- mutate(LifeExpIncomFinal, Year = as.integer(LifeExpIncomFinal$Year))
#subet data for year 2015
leifinal2015 <- LifeExpIncomFinal %>% filter(Year == 2015)
#plot the data
#consider using ggplotly
plot_ly(
data = leifinal2015,
x = ~Income , # Horizontal axis
y = ~LifeExp , # Vertical axis # must be a numeric factor
text = ~geo, #location in the hover text
hovertemplate = paste(
"%{yaxis.title.text}: %{y:}<br>",
"%{xaxis.title.text}: %{x:}<br>",
"Population: %{marker.size:}",
"<extra></extra>"),
color = ~factor(geo),
alpha = 0.5 ,
size = ~Population,
type = "scatter",
mode = "markers"
) %>%
layout(showlegend = FALSE,
title =list(text = "Relationship Between Life Expectancy and GDP",
font = list(family = "Arial",
size = 18,
face = "bold")),
xaxis = list(
title=list(text = 'GDP Per Capita')),
yaxis = list (
title = list(text = 'Life Expectancy')
)
)